//验证银行卡号
export function validateBankCardNumber(cardNumber) {
  let nCheck = 0;
  let bEven = false;
  for (let n = cardNumber.length - 1; n >= 0; n--) {
    let cDigit = cardNumber.charAt(n);
    let nDigit = parseInt(cDigit, 10);
    if (bEven && (nDigit *= 2) > 9) nDigit -= 9;
    nCheck += nDigit;
    bEven = !bEven;
  }
  return (nCheck % 10) === 0;
}

//验证身份证号
export function validateIdCard(idCard) {
  let reg = /^\d{17}(\d|X)$/;
  if (!reg.test(idCard)) {
    return false;
  }

  // 加权因子
  let weightFactor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  // 校验码
  let checkCode = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];

  let sum = 0;
  for (let i = 0; i < 17; i++) {
    sum += Number(idCard[i]) * weightFactor[i];
  }

  let mod = sum % 11;
  if (checkCode[mod] !== idCard[17]) {
    return false;
  }

  return true;
}

//验证姓名
export function validateName(name) {
  let reg = /^[\u4e00-\u9fa5]{2,10}$/;
  return reg.test(name);
}

//验证当前时间在工作日的9:00-15:00之间
export function validateTime() {
  let date = new Date();
  let day = date.getDay();
  let hour = date.getHours();
  return day > 0 && day < 6 && hour > 9 && hour < 15;
}

//验证身份证号
